figure.BasculaFermentacion = new Class({
    Extends: figure.Bascula,

    initialize: function(id, css, value, unit, min, capacity, step) {
        this.parent(id, css, value, unit, min, capacity, step);
    },

    addEvents: function() {
        var controlElement = this.controlElement;
        controlElement.on('growUp', function growUp(event, input, output, sugar, tank, clock, v1, v2, v3) {
            if (figure.stopAnimation) {
                window.setTimeout(function() { growUp(event, input, output, sugar, tank, clock, v1, v2, v3) }, figure.speed);
                return;
            }
            var valueAsInt = parseInt(controlElement[0].value);
            var maxValueAsInt = parseInt(controlElement[0].max);
            if (valueAsInt < maxValueAsInt && parseInt(clock.controlElement[0].value) == 0) {
                figure.pipesStatus[output+'Start'] = false;
                figure.pipesStatus[input+'End'] = true;
                figure.pipesStatus['pipeEtanolStart'] = false;
                figure.pipesStatus['pipeEtanolEnd'] = false;
                tank.drawCrossLine(1,'blue');
                tank.drawCrossLine(2,'blue');
                tank.drawCrossLine(3,'blue');
                tank.unifyLines(3,'blue');
                v1.draw('yellow');
                v2.draw('yellow');
                v3.draw('yellow');
                if (figure.isOpen(input)) {
                    valueAsInt += 500;
                    controlElement[0].value = valueAsInt;
                    controlElement.trigger('change');
                    if (valueAsInt == maxValueAsInt) {
                        figure.pipesStatus['levaduraStart'] = true;
                        figure.pipesStatus['levaduraEnd'] = true;
                    }
                }
            }
            if (valueAsInt == maxValueAsInt) {
                sugar.start = true;
                figure.pipesStatus[input+'End'] = false;
                figure.pipesStatus['pipeEtanolStart'] = true;
                figure.pipesStatus['pipeEtanolEnd'] = true;
                tank.drawCrossLine(1,'green');
                tank.unifyLines(3,'green');
                v1.draw('green');
            }
            if (parseInt(clock.controlElement[0].value) >= 120) {
                figure.pipesStatus[output+'Start'] = true;
                if (figure.isOpen(output)) {
                    valueAsInt -= 500;
                    controlElement[0].value = valueAsInt;
                    controlElement.trigger('change');
                }
                if (valueAsInt == 0) {
                    clock.controlElement[0].value = 0;
                    clock.controlElement.trigger('change');
                    sugar.controlElement[0].value = 6.8;
                    sugar.controlElement.trigger('change');
                }
            }
            window.setTimeout(function() { growUp(event, input, output, sugar, tank, clock, v1, v2, v3) }, figure.speed);
        });
    }

});
